package cn.com.bluemoon.daps.common.mp.mapper;

import cn.com.bluemoon.daps.common.domain.BaseModel;
import cn.com.bluemoon.daps.common.mp.IBmService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 * <p>
 * 抽取model类的基类，必须加上{@link BaseModelMapper}提供mp进行扫描
 * 否则在{@link Wrappers#lambdaQuery()}中使用{@link IBmService#bmLambdaQuery()}的时候调用的是
 * {@link BaseModel#getBmStatus()}的{@link com.baomidou.mybatisplus.core.toolkit.support.SFunction}
 * 的字段lambda方法，而若没有提供本类，会导致项目启动的时候初始化缓存数据中无法找到{@link BaseModel}对应的映射字段导致无法
 * 执行lambda
 * 去除本类后，基于{@link IBmService#bmLambdaQuery()}为条件下，执行{@link BaseMapper#selectCount(Wrapper)}方法
 * 会报:<code>
 * org.mybatis.spring.MyBatisSystemException:
 * nested exception is org.apache.ibatis.builder.BuilderException:
 * Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'.
 * Cause: org.apache.ibatis.ognl.OgnlException:
 * sqlSegment [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException:
 * can not find lambda cache for this property [bmStatus] of entity [cn.com.bluemoon.dap.common.BaseModel]]
 * </code>
 * 原因在于：{@link LambdaUtils#getColumnMap(Class)}基于{@link BaseModel#getClass()}
 * 获取相关缓存为空，导致
 * <p><b>另外，</b>
 * <p>
 * <b>使用抽象的接口方式 无法把{@link BaseModel}加入到{@link LambdaUtils#createColumnCacheMap(TableInfo)} #LAMBDA_MAP}的缓存中</b>
 * 如下：
 * public interface BaseModelMapper<T extends BaseModel<T>> extends BaseMapper<BaseModel<T>> {}
 * public interface BaseModelMapper<T extends BaseModel<T>> extends BaseMapper<BaseModel<?>> {}
 * 而是用：
 * @SuppressWarnings("rawtypes")
 * public interface BaseModelMapper<T extends BaseModel<T>> extends BaseMapper<BaseModel> {}
 * @SuppressWarnings("rawtypes")
 * public interface BaseModelMapper extends BaseMapper<BaseModel> {}
 * </p>
 *  解决方式：在@MapperScan对应的package下增加相关model(实体)的父类对应的Mapper接口，提供mp初始化缓存
 *  比如目前的{@link BaseModel} & {@see BasePublishInfoOfStandard} 需要生成对应的Mapper
 * </p>
 *
 * @author Jarod.Kong
 * @since 2020-09-09
 */
@SuppressWarnings("rawtypes")
public interface BaseModelMapper<T extends BaseModel<T>> extends BaseMapper<BaseModel> {

}